//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    tabbar: {},
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    swiperBg: ['/images/work/swiper1.jpeg', '/images/work/swiper2.jpeg', '/images/work/swiper3.jpeg','/images/work/swiper4.jpeg','/images/work/swiper5.jpeg','/images/work/swiper6.jpeg'],
    navContent: [
      {
        text: '功能1',
        color: 'pink'
      },
      {
        text: '功能2', 
        color: 'red'
      },
      {
        text: '功能3',
        color: 'blue'
      },
      {
        text: '功能4',
        color: 'green'
      },
      {
        text: '功能5',
        color: 'orange'
      },
    ],
    mainContent: [
      {
        text: '功能A',
        color: 'green'
      },
      {
        text: '功能B', 
        color: 'pink'
      },
      {
        text: '功能C',
        color: 'purple'
      },
      {
        text: '功能D',
        color: 'yellow'
      },
      {
        text: '功能E',
        color: 'black'
      },
      {
        text: '功能F',
        color: 'gray'
      },
      {
        text: '功能G', 
        color: 'beige'
      },
      {
        text: '功能H',
        color: 'blue'
      },
      {
        text: '功能I',
        color: 'orchid'
      },
      {
        text: '功能J',
        color: 'mediumturquoise'
      },
      {
        text: '',
        color: ''
      },
      {
        text: '',
        color: ''
      }
    ],
    maskContent: [
      {
        text: '功能1',
        color: 'pink'
      },
      {
        text: '功能2', 
        color: 'red'
      },
      {
        text: '功能3',
        color: 'blue'
      },
      {
        text: '功能4',
        color: 'green'
      },
      {
        text: '功能5',
        color: 'orange'
      },
      {
        text: '功能3',
        color: 'blue'
      },
      {
        text: '功能4',
        color: 'green'
      },
      {
        text: '功能4',
        color: 'green'
      },
      {
        text: '功能3',
        color: 'blue'
      },
      {
        text: '功能1',
        color: 'pink'
      },
      {
        text: '功能2', 
        color: 'red'
      }
    ],
    // 此页面 页面内容距最顶部的距离
    height: app.globalData.statusBarHeight + app.globalData.navBarHeight,
    isMask: false
  },
  
  onLoad: function () {
    app.editTabbar();
   
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    } else if (this.data.canIUse){
      app.userInfoReadyCallback = res => {
        this.setData({
          userInfo: res.userInfo,
          hasUserInfo: true
        })
      }
    } else {
      // 在没有 open-type=getUserInfo 版本的兼容处理
      wx.getUserInfo({
        success: res => {
          app.globalData.userInfo = res.userInfo
          this.setData({
            userInfo: res.userInfo,
            hasUserInfo: true
          })
        }
      })
    }
  },
  getUserInfo(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  openMask(e) {
    const text = e.currentTarget.dataset.text;
    if(text === '功能B'){
      this.setData({
        isMask: true
      })
    }else{
      this.setData({
        isMask: false
      })
    }
  },
  closeMask(){
    this.setData({
      isMask: false
    })
  }
})
